//
//  DetaiPlayViewController.m
//  Travel
//
//  Created by lanou3g on 15/12/11.
//  Copyright © 2015年 涂晓雨. All rights reserved.
//

#import "DetaiPlayViewController.h"
#import "SDCycleScrollView.h"
#import "PlayDataHelper.h"
#import "detailModel.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "commentViewController.h"
#import "topicViewController.h"
#import "IntroduceViewController.h"
#import "PreferenceViewController.h"
@interface DetaiPlayViewController ()
@property(nonatomic,strong)UIView *cycleView;
@property(nonatomic,strong)MKMapView *mapView1;
@property(nonatomic,strong)CLGeocoder *geocoder;
@property(nonatomic,strong)UIView *buttonView ;
@property(nonatomic,strong)NSMutableArray *detailArray;
@end

@implementation DetaiPlayViewController


-(NSMutableArray *)detailArray {
    if (_detailArray == nil) {
        _detailArray = [NSMutableArray array];
    }
    return _detailArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];

    [self addMap];
    [[PlayDataHelper sharePlayDataHelper]detailData:self.model.Id.integerValue];
  
    __weak typeof(self) weakSelf = self;
    [PlayDataHelper sharePlayDataHelper].setValue1 = ^(NSMutableArray *arr){
        [weakSelf headerScroller:arr];
     
    };
    [PlayDataHelper sharePlayDataHelper].setValue3 = ^(NSMutableArray *arr){
    
        weakSelf.detailArray = arr;
    };
 
    
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addAnnotationViewWithTapGes:)];
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 230, self.view.frame.size.width, 400)];
    [self.view addSubview:view1];
        [view1 addGestureRecognizer:tap];
    
   
}

-(void)addAnnotationViewWithTapGes:(UITapGestureRecognizer *)tap{

    [self.cycleView removeFromSuperview];
    [self.buttonView removeFromSuperview];

}

//轮播图
-(void)headerScroller:(NSArray *)arr{
    self.cycleView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 180)];
    self.cycleView.backgroundColor = [UIColor redColor];
    SDCycleScrollView *sdc = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 180) imageURLStringsGroup:nil];
    sdc.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    NSMutableArray *array = [NSMutableArray array];
    for (detailModel *model in arr) {
        [array addObject:model.NewPath];
    }
    sdc.imageURLStringsGroup = array;
    sdc.autoScrollTimeInterval = 5;
    self.cycleView = sdc;
     self.cycleView.userInteractionEnabled = NO;
   [self.view addSubview:self.cycleView];
    self.cycleView.userInteractionEnabled = YES;
    
    self.buttonView = [[UIView alloc]initWithFrame:CGRectMake(0, 244, self.view.frame.size.width, 50)];
    self.buttonView.backgroundColor = [UIColor whiteColor];
    self.buttonView.alpha = 0.5;
    [self.view addSubview:self.buttonView];
    self.buttonView.userInteractionEnabled = YES;
    
    UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(10,-25 ,50, 50)];
    [button1 setBackgroundColor:[UIColor cyanColor]];
    [self.buttonView addSubview:button1];
    button1.layer.masksToBounds = YES;
    button1.layer.cornerRadius = 25;
    [button1 setTitle:@"特惠" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(action1) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(80,-25 ,50, 50)];
    [button2 setBackgroundColor:[UIColor cyanColor]];
    [self.buttonView addSubview:button2];
    button2.layer.masksToBounds = YES;
    button2.layer.cornerRadius = 25;
     [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button2 setTitle:@"简介" forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(action2) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *button3 = [[UIButton alloc]initWithFrame:CGRectMake(150,-25 ,50, 50)];
    [button3 setBackgroundColor:[UIColor cyanColor]];
    [self.buttonView addSubview:button3];
    button3.layer.masksToBounds = YES;
    button3.layer.cornerRadius = 25;
     [button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button3 setTitle:@"评论" forState:UIControlStateNormal];
    [button3 addTarget:self action:@selector(action3) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *button4 = [[UIButton alloc]initWithFrame:CGRectMake(220,-25 ,50, 50)];
    [button4 setBackgroundColor:[UIColor cyanColor]];
    [self.buttonView addSubview:button4];
    button4.layer.masksToBounds = YES;
    button4.layer.cornerRadius = 25;
     [button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button4 setTitle:@"乐题" forState:UIControlStateNormal];
    [button4 addTarget:self action:@selector(action4) forControlEvents:UIControlEventTouchUpInside];
    
}


-(void)action1{
    UIStoryboard  *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    PreferenceViewController *login = [story instantiateViewControllerWithIdentifier:@"login"];
//    login.city = self.cityName;
//    NSLog(@"city:%@",login.city);
    [self presentViewController:login animated:YES completion:nil];
    
    
}

-(void)action2{
    IntroduceViewController *introduce = [[IntroduceViewController alloc]init];
    introduce.model = self.model;
    introduce.array = self.detailArray;
    [self.navigationController pushViewController:introduce animated:YES];
    
}


-(void)action3{
    commentViewController *comment = [[commentViewController alloc]init];
    [self.navigationController pushViewController:comment animated:YES];
}


-(void)action4{
    topicViewController *topic = [[topicViewController alloc]init];
    [self.navigationController pushViewController:topic animated:YES];
}
//添加地图
-(void)addMap{
    
    
    //设置地图
    self.mapView1 = [[MKMapView alloc]initWithFrame:self.view.bounds];
    //设置地图的类型
    self.mapView1.mapType = MKMapTypeStandard;
    self.mapView1.scrollEnabled = YES;
    //添加
    [self.view addSubview: self.mapView1];
    self.mapView1.showsUserLocation = NO;
    self.geocoder = [[CLGeocoder alloc]init];
    double lat = self.model.lat.doubleValue;
    double lng = self.model.lng.doubleValue;
    CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(lat, lng);
    float zoomlevel = 0.005;
    MKCoordinateRegion region = MKCoordinateRegionMake(coords, MKCoordinateSpanMake(zoomlevel, zoomlevel));
    [_mapView1 setRegion:region animated:YES];
    MKPointAnnotation *pAnn = [[MKPointAnnotation alloc]init];
    pAnn.coordinate = coords;
    pAnn.title = self.model.Name;
    [_mapView1 addAnnotation:pAnn];

}


-(void)search{

 

}
@end
